﻿using HY.Common;
using System;

namespace WpfApp.ViewModels
{
    /*
     * 使用插件实现INotifyPropertyChanged的简单封装，也可自己实现
     * SetProperty 判断 _Number2 和 value 是否相等，如果不相等就为 _Number2 赋值并触发 OnPropertyChanged 事件
     */
    /// <summary>
    /// BindViewModel
    /// </summary>
    internal class BindViewModel : BindableBase
    {
        /// <summary>
        /// 单项绑定示例，不需继承INotifyPropertyChanged
        /// </summary>
        public int Number1 { get; set; }

        private int _Number2;
        /// <summary>
        /// 用于验证单项绑定时，Model的值已被修改
        /// </summary>
        public int Number2
        {
            get
            {
                return _Number2;
            }
            set
            {
                SetProperty(ref _Number2, value);
            }
        }


        private int _Number3;
        /// <summary>
        /// 修改Number3时，同时对Number4进行操作
        /// </summary>
        public int Number3
        {
            get
            {
                return _Number3;
            }
            set
            {
                SetProperty(ref _Number3, value, new Action(() => Number4 = value));
            }
        }

        private int _Number4;
        /// <summary>
        /// 用于验证修改Number3时，对Number4的操作可展现到UI
        /// </summary>
        public int Number4
        {
            get
            {
                return _Number4;
            }
            set
            {
                SetProperty(ref _Number4, value);
            }
        }
    }
}
